using System.Reflection;
using System.Utility.System.Utility.Resources;

namespace System.Utility.Data.Validation
{
	public abstract class Validator
	{
		private PropertyInfo _PropertyInfo;

		private string _ErrorMsg;

		public string ErrorMsg
		{
			get
			{
				return _ErrorMsg;
			}
			protected set
			{
				_ErrorMsg = value;
			}
		}

		public PropertyInfo PropertyInfo
		{
			get
			{
				return _PropertyInfo;
			}
		}

		protected Validator(string errorMsg, string text, PropertyInfo propertyInfo)
		{
			_ErrorMsg = errorMsg;
			if (string.IsNullOrEmpty(errorMsg))
			{
				_ErrorMsg = string.Format(DefaultErrorMessages.Default, text);
			}
			_PropertyInfo = propertyInfo;
		}

		public bool IsValid(object instance)
		{
			Guard.ArgumentNotNull(instance, "instance");
			object value = _PropertyInfo.GetValue(instance, null);
			return Validation(value);
		}

		protected abstract bool Validation(object value);
	}
}